package com.bsoft.exchange.controller.appointmentandregistration;

import java.util.List;
import java.util.Map;

import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.bsoft.exchange.domain.ListTakeNumber;
import com.bsoft.exchange.domain.RegisterDomain;
import com.bsoft.exchange.domain.TakeNumberDomain;
import com.bsoft.exchange.pojo.HisOrderNumberPojo;
import com.bsoft.exchange.pojo.ListTakeNumberPojo;
import com.bsoft.exchange.pojo.PaymentBudgetPojo;
import com.bsoft.exchange.pojo.TakeNumberPojo;
import com.bsoft.exchange.response.ResponseEntity;
import com.bsoft.exchange.response.ResponseStatus;
import com.bsoft.exchange.service.TakenumberService;
import com.bsoft.exchange.util.BaseResponse;
import com.bsoft.exchange.util.Constant;
import com.bsoft.exchange.vo.RegisterVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api("swagger测试控制器")
@RestController
@RequestMapping(value = "takenumber")
public class TakenumberController {
	
	@Autowired
    Mapper dozerMapper;
	
	@Autowired
	TakenumberService takenumberService;
	
	
//	@ApiOperation(value = "挂号支付预结算/签到取号预结算", 
//			notes = "入参：hospitalCode：医院ID，医院系统身份标识 ; hisOrderNumber ：医院挂号流水号 ")
//	@ResponseBody
//	@RequestMapping(value = "/paymentBudget",method = RequestMethod.POST,produces = "application/json")
//	public ResponseEntity<Object> paymentBudget(@RequestBody PaymentBudgetPojo paymentBudgetPojo) {
//		//Map<String, Object> map = null;
//		ResponseEntity<Object> entry = new ResponseEntity<>();
//		
//		BaseResponse<Map<String, Object>> response =  new BaseResponse<>();
//
//		try {
//
//			response = TakenumberService.paymentBudget(paymentBudgetPojo);
//		} catch (Exception e) {
//			e.printStackTrace();
//			entry.setCode(ResponseStatus.ERROR_CODE);
//			entry.setMessage("处理失败");
//		}
//		 if (response.getCode()==Constant.errorTag){
//			 	entry.setCode(0);
//	        	entry.setMessage(response.getMessage());
//	            return entry;
//	        }
//		 
////		entry.setCode(ResponseStatus.SUCCESS_CODE);
////		entry.setMessage("处理成功");
//		entry.setData(response.getData());
//		
//		return entry;
//	}

	
	@ApiOperation(value = "签到取号列表", notes = "入参：hospitalCode：机构id ； patientMedicalCardList ：诊疗卡集合 ；patientMedicalCardType：诊疗卡类型；"
			+ "patientMedicalCardNumber：诊疗卡号码；patientCodelist：患者标识集合；patientCode ：患者编号； patientIdentityCardlist：证件集合；"
			+ "patientIdentityCardType：患者证件类型；patientIdentityCardNumber：证件号码")
	@ResponseBody
	@RequestMapping(value = "/listTakeNumber",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<Object> listTakeNumber(@RequestBody ListTakeNumberPojo listTakeNumberPojo) {
		BaseResponse<List<ListTakeNumber>> responseEntry = new BaseResponse<>();
		ResponseEntity<Object> entry = new ResponseEntity<>();
		responseEntry  = takenumberService.listTakeNumber(listTakeNumberPojo);
		
		if ("1".equals(responseEntry.getCode().toString())) {
			entry.setCode(ResponseStatus.SUCCESS_CODE);
		}else if("0".equals(responseEntry.getCode().toString())) {
			entry.setCode(ResponseStatus.ERROR_CODE);
		}
		entry.setMessage(responseEntry.getMessage());
		entry.setData(responseEntry.getData());
		
		return entry;
	}
	
	
	@ApiOperation(value = "获取挂号单", notes = "入参：hospitalCode：医院ID ； hisOrderNumber ：挂号流水号  ")
	@ResponseBody
	@RequestMapping(value = "/getRegistrationForm",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<RegisterVo> getRegistrationForm(@RequestBody HisOrderNumberPojo hisOrderNumberPojo) {
		
		ResponseEntity<RegisterVo> entry = new ResponseEntity();
		
		//System.out.println("根据机构id【"+hospitalCode+"】，挂号流水号【"+hisOrderNumber+"】获取挂号单信息");

		RegisterDomain register = takenumberService.getRegistrationForm( hisOrderNumberPojo.getOrganizationId(), hisOrderNumberPojo.getOrderId());
		
		//实体bean转换
		if(register!=null){
			RegisterVo registerVo = dozerMapper.map(register, RegisterVo.class);
			entry.setData(registerVo);
		}

		return entry;
	}
	
	@ApiOperation(value = "签到取号", notes = "入参：hospitalCode：医院ID ； hisOrderNumber ：预约序号  ")
	@ResponseBody
	@RequestMapping(value = "/takenumber",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<TakeNumberDomain> getRegistrationForm(@RequestBody TakeNumberPojo takeNumberPojo) {
		ResponseEntity<TakeNumberDomain> entity=new ResponseEntity();
		ResponseEntity<TakeNumberDomain> entry = new ResponseEntity();
		
		//System.out.println("根据机构id【"+hospitalCode+"】，挂号流水号【"+hisOrderNumber+"】获取挂号单信息");
		try{
		BaseResponse<TakeNumberDomain> baseResponse = takenumberService.takeNumber(takeNumberPojo) ;
		entity.setData(baseResponse.getData());
		entity.setMessage(baseResponse.getMessage());
		}
		catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

		return entity;
	}
	
//	@ApiOperation(value = "支付确认", notes = "入参：hospitalCode：医院ID; hisOrderNumber ：医院挂号流水号,payMode ：支付方式,"
//			+ "agtOrderNumber ：对应收单机构,payAmount ：付款金额,notify ：支付成功时的通知信息,payTime ：实际支付时间yyyy-MM-dd HH:mm:ss")
//	@ResponseBody
//	@RequestMapping(value = "/paymentConfirm",method = RequestMethod.POST,produces = "application/json")
//	public ResponseEntity<Object> paymentConfirm(@RequestBody AppointmentPayPojo appointmentPayPojo) {
//		Map<String, Object> map = null;
//		ResponseEntity<Object> entry = new ResponseEntity<>();
//		entry.setCode(ResponseStatus.SUCCESS_CODE);
//		entry.setMessage("处理成功");
//
//		try {
//			map = TakenumberService.paymentConfirm(appointmentPayPojo);
//		} catch (Exception e) {
//			e.printStackTrace();
//			entry.setCode(ResponseStatus.ERROR_CODE);
//			entry.setMessage("处理失败");
//		}
//		entry.setData(map);
//		
//		return entry;
//	}
	
	
}
